# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=flake8
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=6.0.0
pkgrel=1
pkgdesc="The modular source code checker: pep8, pyflakes and co"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/pycqa/flake8"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-pyflakes"
         "${MINGW_PACKAGE_PREFIX}-python-mccabe"
         "${MINGW_PACKAGE_PREFIX}-python-pycodestyle")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('c61007e76655af75e6785a931f452915b371dc48f56efd765247c8fe68f2b181')

prepare() {
  cd "${_realname}-${pkgver}"
  # disable overly restrictive dependency pinning
  sed -i -e 's|,<[0-9=.]*||' setup.cfg

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  rm -rf python-build-${MSYSTEM}| true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python setup.py pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
